package net.xo68.destiny.manager.mapper;


import net.xo68.destiny.manager.entity.SimpleTrigger;
import org.apache.ibatis.annotations.*;
import java.util.List;

/** 
 * SimpleTrigger mybatis mapper
 * @author wuxie(16349023@qq.com)
 * @date 2020年12月21日 21:43:52
 *
 */
public interface SimpleTriggerMapper {


	
	@Select("SELECT * FROM destiny_simple_trigger WHERE job_id = #{jobId}")
    @Results(value = { 
    @Result(id = true, column = "job_id", property = "jobId"),
        @Result(column = "repeat_count", property = "repeatCount"),
        @Result(column = "repeat_interval", property = "repeatInterval"),
        @Result(column = "times_fired", property = "timesFired")
    })
    SimpleTrigger find(@Param("jobId") Long jobId);
	
	@Select("SELECT * FROM destiny_simple_trigger")
    @Results(value = { 
    @Result(id = true, column = "job_id", property = "jobId"),
        @Result(column = "repeat_count", property = "repeatCount"),
        @Result(column = "repeat_interval", property = "repeatInterval"),
        @Result(column = "times_fired", property = "timesFired")
    })
    List<SimpleTrigger> list();

    @Select("<script>" +
            "SELECT * FROM destiny_simple_trigger" +
            " where job_id in " +
            "<foreach item='jobId' index='index' collection='jobs' open='(' separator=',' close=')'>" +
            "#{jobId}" +
            "</foreach>" +
            "</script>")
    @Results(value = {
            @Result(id = true, column = "job_id", property = "jobId"),
            @Result(column = "repeat_count", property = "repeatCount"),
            @Result(column = "repeat_interval", property = "repeatInterval"),
            @Result(column = "times_fired", property = "timesFired")
    })
    List<SimpleTrigger> listByJobs(@Param("jobs")List<Long> jobs);
	
	@Insert("insert into destiny_simple_trigger (job_id ,repeat_count ,repeat_interval ,times_fired ) values (#{jobId} , #{repeatCount} , #{repeatInterval} , #{timesFired}  )")
    @Options(useGeneratedKeys = true, keyProperty = "jobId")
    int insert(SimpleTrigger simpleTrigger);
	
	@Update({"update destiny_simple_trigger set",
      " repeat_count=#{repeatCount}, repeat_interval=#{repeatInterval}, times_fired=#{timesFired} ",
      "where job_id = #{jobId}"
    })
    int update(SimpleTrigger simpleTrigger);

	@Delete("delete FROM destiny_simple_trigger WHERE job_id = #{jobId}")
	int delete(@Param("jobId") Long jobId);
}